<template>
  <div class="container">
    <baseTable
      :tableSetting="serviceListSetting"
      :tableData="serviceListData"
      ref="serviceList"
    ></baseTable>
  </div>
</template>

<script>
import {
  overhaulApplicationList, //根据工单id查询关联的检修申请单
} from "@/api/orderManagement/overhaulApplication";
export default {
  props: {
    orderId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      serviceListData: [],
      serviceListSetting: {
        title: "",
        indexShow: true, // 序号显示
        //height: 200,
        autoHeight:true,
        column: [
          {
            label: "检修单编号",
            prop: "code",
            width: "110px",
          },
          {
            label: "标题",
            prop: "title",
          },
          {
            label: "设备管理单位",
            prop: "deptManageName",
          },
          {
            label: "设备",
            prop: "orderEquipPoList",
            scopeType: "formate",
            method: (row) => {
              let equipList = row.orderEquipPoList || [];
              let name = [];
              if (equipList.length > 0) {
                equipList.map((i) => {
                  name.push(i.equipmentName);
                });
              }
              return name.toString();
            },
          },
          {
            label: "作业单位",
            prop: "workDeptPoList",
            scopeType: "formate",
            method: (row) => {
              let worklist = row.workDeptPoList || [];
              let name = [];
              if (worklist.length > 0) {
                worklist.map((i) => {
                  name.push(i.workDeptName);
                });
              }
              return name.toString();
            },
          },
          {
            label: "计划开始时间",
            prop: "startTime",
            width: "150px",
          },
          {
            label: "计划结束时间",
            prop: "endTime",
            width: "150px",
          },
          {
            label: "状态",
            prop: "status",
            formatter: (row) => {
              let value = row.status;
              return (
                this.$store.getters["fineDirtDataName"](
                  "order_application_status",
                  value
                ) || value
              );
            },
            width: "90px",
          },
        ],
        data: [],
        rowClick: async (row) => {
          /* 工作票详情 */
          let { id, ticketType } = row;
          let routerForm = {
            id: id,
            ticketType,
            pageType: "edit",
          };
          this.goToDetails(routerForm);
        },
      },
    };
  },
  created() {},
  mounted() {
    this.getWorkingTicketData();
  },
  methods: {
    //获取工作票信息
    getWorkingTicketData() {
      let form = {
        orderCode: this.orderId,
        page: 1,
        pageSize: 30,
      };
      overhaulApplicationList(form).then((res) => {
        let data = res.data.list || [];
        this.serviceListData = data;
        this.$emit("haveData", data.length > 0 ? true : false);
        this.$refs.serviceList.setTableData(data);
      });
    },
    goToDetails(data) {
      const { href } = this.$router.resolve({
        name: "overhaulApplicationDetails",
        query: data,
      });
      window.open(href, "_blank");
    },
  },
};
</script>